//TileForwardAnimTextureMapFX.h
//Created 09/01/14
//Created By Daniel Bowler
//
//Effect which supports animation. Used for submodels which only
//require a texture to be applied. 

#include "AbstractFX.h"

class TileForwardAnimTextureMapFX : public AbstractFX
{
	//Shader manager will create & destroy an instance of this class.
	friend ShaderManager;
public:
	//Per vertex structure.
	struct PerVertex
	{
		PerVertex()
		{
			for (UINT i = 0; i < 3; i++)
				Weights[i] = 0.0f;
			for (UINT i = 0; i < 4; i++)
				BoneIndicies[i] = 0;
		}
		XMFLOAT3 PosL;
		XMFLOAT3 NormalL;
		XMFLOAT2 Tex;
		float Weights[3];
		UINT BoneIndicies[4];
	};

	//Setters for the shader variables and resources.
	void SetShaderResources(ID3D11ShaderResourceView* texture);
	void SetPerObjectCbuffer(CXMMATRIX& world, CXMMATRIX& worldInvTrans, 
		CXMMATRIX& worldViewProj,
		CXMMATRIX& texTrans, Material mat, 
		CXMMATRIX& worldView);

	//Animation setters.
	void SetAnimationBoneTransformArray(XMFLOAT4X4* matArr, unsigned count); 

	//Set lighting data.
	void SetLightingData(XMFLOAT3& eye, 
		DirectionalLight* dLights, unsigned dLightCount,
		ID3D11ShaderResourceView* lightListIndexBuffer, 
		ID3D11ShaderResourceView* lightListStartEndBuffer);

	//Sets hemispherical ambient colour data
	void SetHemisphericalData(XMFLOAT3 &hemiColDown, XMFLOAT3 &hemiColRange);

	//Set SSAO Map and transform data
	void SetSSAOData(ID3D11ShaderResourceView* ssaoTex, CXMMATRIX &transform);

	//Sets the environment map - Note Material::Reflection determins how
	//much of the enviromnet is reflected on the model. Very shiny models
	//should have more reflectivity and mat models less. Also, flat models
	//should NOT have any reflectivity because the effect looks shit. 
	void SetEnvironmentMap(ID3D11ShaderResourceView* envCubeMap);

	//Sets render target dimentions - shader manager calls this. 
	void SetRTDimensions(unsigned width, unsigned height);
	//Set Light List Buffer (Global lights buffer - Shader Manager can call this)
	void SetLightListBuffer(ID3D11ShaderResourceView* lightListBuffer);

	//Sets shadow map
	void SetShadowMap(ID3D11ShaderResourceView* shadowMap);
	void SetShadowMapMatricies(CXMMATRIX &view, CXMMATRIX &proj, CXMMATRIX &toTex);

private:
	//Constructor and destructor
	TileForwardAnimTextureMapFX(ID3D11Device* device);
	~TileForwardAnimTextureMapFX();
	//Disable copy constructor and = operator
	TileForwardAnimTextureMapFX(TileForwardAnimTextureMapFX& other);
	TileForwardAnimTextureMapFX& operator= (TileForwardAnimTextureMapFX& other);

	//Override these to aid in creating the FX class properly.
	void InitInputLayout(ID3D11Device* device);
	void InitShaderVariablePointers();

private:
	//Shader Variables.
	ID3DX11EffectVectorVariable* eyePosVar;
	ID3DX11EffectVariable* materialVar;

	//Per object
	ID3DX11EffectMatrixVariable* worldVar;
	ID3DX11EffectMatrixVariable* worldInvTransVar;
	ID3DX11EffectMatrixVariable* worldViewProjVar;
	ID3DX11EffectMatrixVariable* texTransformVar;
	
	//Shader Resources (SRVs)
	ID3DX11EffectShaderResourceVariable* diffuseMapVar;

	//Animation data
	ID3DX11EffectMatrixVariable* boneTransVar;

	//Render dimensions
	ID3DX11EffectScalarVariable* rtWidthVar;
	ID3DX11EffectScalarVariable* rtHeightVar;	
	
	//Direc Lights
	ID3DX11EffectVariable* direcLightVar;
	ID3DX11EffectScalarVariable* direcLightCountVar;

	//Point/Spot lights - Tile Forward System
	ID3DX11EffectShaderResourceVariable* llbVar;
	ID3DX11EffectShaderResourceVariable* llibVar;
	ID3DX11EffectShaderResourceVariable* llsebVar;

	//Hemispheric Ambient lighting colours
	ID3DX11EffectVectorVariable* hemiColDownVar;
	ID3DX11EffectVectorVariable* hemiColRangeVar;
	
	//SSAO
	ID3DX11EffectMatrixVariable* worldViewVar;
	ID3DX11EffectShaderResourceVariable* ssaoMapVar;
	ID3DX11EffectMatrixVariable* ssaoWorldViewProjTexVar;

	//Environment map
	ID3DX11EffectShaderResourceVariable* envMapVar;
	
	//Shadow Map
	ID3DX11EffectShaderResourceVariable* shadowMapVar;
	ID3DX11EffectMatrixVariable* shadowMapViewVar;
	ID3DX11EffectMatrixVariable* shadowMapProjVar;
	ID3DX11EffectMatrixVariable* shadowMapToTexVar;
};